
/* JavaScript content from js/CustomAuthenticatorRealmChallengeHandler.js in folder common */
/*
 *  Licensed Materials - Property of IBM
 *  5725-G92 (C) Copyright IBM Corp. 2006, 2013. All Rights Reserved.
 *  US Government Users Restricted Rights - Use, duplication or
 *  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */// /////////////////////
// Challenge Handler
// /////////////////////
var customAuthenticatorRealmChallengeHandler = WL.Client
		.createChallengeHandler("CustomAuthenticatorRealm");

customAuthenticatorRealmChallengeHandler.isCustomResponse = function(response) {
	if (!response || !response.responseJSON) {
		return false;
	}

	if (response.responseJSON.authStatus)
		return true;
	else
		return false;
};

customAuthenticatorRealmChallengeHandler.handleChallenge = function(response) {
	var authStatus = response.responseJSON.authStatus;

	if (authStatus == "required") {
	
		busyIndicator.hide();
		$.mobile.changePage("Login.html",{changeHash : false,transition: "pop"});
		$('#login').show();
		$('#passwordInputField').val('');
		if (response.responseJSON.errorMessage) {
			alert(response.responseJSON.errorMessage);
		}
	} else if (authStatus == "complete") {
	
		$.mobile.changePage("AllProjects.html", {changeHash : false,transition: "pop"});
	/*	$.mobile.changePage("AllProjects.html",{transition :"pop", allowSamePageTransition : true});
		*/
		customAuthenticatorRealmChallengeHandler.submitSuccess();
	}

};

customAuthenticatorRealmChallengeHandler.submitLoginFormCallback = function(
		response) {
	var isLoginFormResponse = customAuthenticatorRealmChallengeHandler
			.isCustomResponse(response);
	if (isLoginFormResponse) {
		customAuthenticatorRealmChallengeHandler.handleChallenge(response);
	}
};


customAuthenticatorRealmChallengeHandler.login = function() {

					var reqURL = '/my_custom_auth_request_url';
					var options = {};
					options.parameters = {
						username : $('#usernameInputField').val(),
						password : $('#passwordInputField').val()
					};
					options.headers = {};
					customAuthenticatorRealmChallengeHandler
							.submitLoginForm(
									reqURL,
									options,
									customAuthenticatorRealmChallengeHandler.submitLoginFormCallback);
				};
/*
 * $('#cancelButton').bind('click', function () { $('#AppBody').show();
 * $('#AuthBody').hide();
 * customAuthenticatorRealmChallengeHandler.submitFailure(); });
 */

